package xdu.lz.stage2_design_pattern.chapter17_worker_thread_pattern;

import java.util.Random;

public class WorkerThread extends Thread {

    private final Channel channel;

    private static final Random random  = new Random(System.currentTimeMillis());

    public WorkerThread(String name, Channel channel) {
        super(name);
        this.channel = channel;
    }

    @Override
    public void run() {
        //装配工人不断从传送带拿东西
        while (true){
            //从传送带拿
            Request poll = channel.poll();
            //模拟干工作
            poll.execute();
            try {
                Thread.sleep(random.nextInt(1000));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
